/*
https://leetcode.cn/problems/maximum-subarray/
53. 最大子数组和
*/
class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int leng=nums.size();
        if(leng==1) return nums[0];
    int cur = nums[0];
    int maxx = cur;
    for (int i = 1; i < leng; i++) {
        cur = max(cur, 0) + nums[i];
        //记录最大值
        maxx = max(maxx, cur);
    }
    return maxx;
    }
};